package main

//#link: https://leetcode-cn.com/problems/power-of-two/
import (
	"fmt"
	"strings"
)

func main() {
	n := 4
	fmt.Println(isPowerOfTwo(n))
}

//n&n-1 例如:4->100,3->011 所以4&3==0
func isPowerOfTwo(n int) bool {
	return n > 0 && (n&(n-1) == 0)
}

//利用了循环
func isPowerOfTwoByFor(n int) bool {
	numStr := fmt.Sprintf("%b", n)
	if numStr[0] != '1' {
		return false
	} else {
		if strings.Count(numStr, "1") > 1 {
			return false
		}
	}
	return true
}
